home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_084 / hunkpad / avery / hunkpad.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  62 lines

  1. /* hunkpad.c -- written by Aaron Avery -- released 6/12/87 */
  2.  
  3. #include <libraries/dos.h>
  4. #include <exec/memory.h>
  5.  
  6. extern struct FileInfoBlock *AllocMem();
  7. extern struct FileLock *Lock();
  8.  
  9. main(argc, argv)
  10. int argc;
  11. char *argv[];
  12. {
  13. int i, size;
  14. char *pad;
  15. long test, file;
  16. struct FileInfoBlock *FBlock;
  17. struct FileLock      *FLock;
  18.  
  19.    if(argc != 2)
  20.       { printf("Usage: %s <file>\n",argv[0]); exit(0); }
  21.  
  22.    pad = "\0\0\003\362"; /* hunk_end to pad with */
  23.  
  24.    if(!(FLock = Lock(argv[1],ACCESS_READ)))
  25.       { printf("Couldn't find file named: %s\n",argv[1]); exit(0L); }
  26.  
  27.    file = Open(argv[1],MODE_OLDFILE);
  28.    if(FBlock = AllocMem(sizeof(*FBlock), MEMF_CHIP))
  29.       {
  30.       if(Examine(FLock,FBlock)) /* fill FBlock */
  31.          {
  32.          size = (int)(FBlock->fib_Size & 127); /* size mod 128 */
  33.          if(size) /* needs padding */
  34.             {
  35.             Read(file,&test,4L);
  36.             if(test == 0x000003f3) /* first longword identifies tools */
  37.                {
  38.                if(Seek(file,0L,OFFSET_END) != -1) /* go to end of file */
  39.                   {
  40.                   for(i=0;i < ((128 - size) >> 2);i++)
  41.                      Write(file,pad,4L); /* assume we can write */
  42.                   }                     /* if we get this far  */
  43.                else
  44.                   printf("Dos error! (Seek())\n");
  45.                }
  46.             else
  47.                printf("%s is not a tool.\n",argv[1]);
  48.             }
  49.          else
  50.             printf("File length is already divisible by 128.\n");
  51.          }
  52.       else
  53.          printf("Dos Error! (Examine())\n");
  54.       FreeMem(FBlock,sizeof(*FBlock));
  55.       }
  56.    else
  57.       printf("Not enough memory!\n");
  58.  
  59.    Close(file);
  60.    UnLock(FLock);
  61. }
  62.